package icu.feigroup.domain.trade.service.settlement.factory;

import icu.feigroup.domain.trade.model.entity.*;
import icu.feigroup.domain.trade.service.settlement.filter.EndRuleFilter;
import icu.feigroup.domain.trade.service.settlement.filter.OutTradeNoRuleFilter;
import icu.feigroup.domain.trade.service.settlement.filter.SCRuleFilter;
import icu.feigroup.domain.trade.service.settlement.filter.SettableRuleFilter;
import icu.feigroup.types.design.framwork.link.model2.LinkArmory;
import icu.feigroup.types.design.framwork.link.model2.chain.BusinessLinkedList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * projectName:icu.feigroup.domain.trade.service.locak.factory
 *
 * @author 飞
 * @since 2025/2/25 16:01
 * description:交易结算规则过滤工厂
 */
@Slf4j
@Service
public class TradeSettlementRuleFilterFactory {


    @Bean("tradeSettlementRuleFilter")
    public BusinessLinkedList<TradeSettlementRuleCommandEntity,
            TradeSettlementRuleFilterFactory.DynamicContext, TradeSettlementRuleFilterBackEntity> tradeSettlementRuleFilter(
            SCRuleFilter scRuleFilter,
            OutTradeNoRuleFilter outTradeNoRuleFilter,
            SettableRuleFilter settableRuleFilter,
            EndRuleFilter endRuleFilter) {

        // 组装链
        LinkArmory<TradeSettlementRuleCommandEntity, TradeSettlementRuleFilterFactory.DynamicContext, TradeSettlementRuleFilterBackEntity> linkArmory =
                new LinkArmory<>("交易结算规则过滤链", scRuleFilter, outTradeNoRuleFilter, settableRuleFilter, endRuleFilter);

        // 链对象
        return linkArmory.getLogicLink();
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DynamicContext{
        private MarketPayOrderEntity marketPayOrderEntity;
        private GroupBuyTeamEntity groupBuyTeamEntity;
    }
}
